package com.chuanggou.web.gateway.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

@Service
public class AuthService {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //从cookie中获取jti的值
    public String getJtiFromCookie(ServerHttpRequest request){
        HttpCookie httpCookie = request.getCookies().getFirst("uid");


        //判断cookie不为null
        if (httpCookie != null){
            //将cookie中的值返回
            String jti = httpCookie.getValue();
            return jti;
        }

        return null;
    }

    //从redis获取jwt令牌
    public String getJwtFromRedis(String jti){
        String jwt = stringRedisTemplate.boundValueOps(jti).get();
        return jwt;
    }
}
